<template>
  <el-container class="layout">
    <!-- 侧边导航：固定不动 -->
    <el-aside width="200px" class="sidebar">
      <!-- LOGO 区域 -->
      <div class="logo-box">
        <div class="title">驴肉火烧系统</div>
        <img src="/images/indeximage.png" alt="logo" class="sidebar-img" />
      </div>

      <!-- 菜单 -->
      <el-menu
        :default-active="activeMenu"
        router
        class="h-full border-none"
      >
        <el-menu-item index="/customer">
          <i class="el-icon-food"></i>
          <span>点餐</span>
        </el-menu-item>
        <el-menu-item index="/cart">
          <i class="el-icon-shopping-cart-full"></i>
          <span>购物车</span>
        </el-menu-item>
        <el-menu-item index="/orders">
          <i class="el-icon-document"></i>
          <span>订单</span>
        </el-menu-item>
        <el-menu-item index="/admin">
          <i class="el-icon-setting"></i>
          <span>后台管理</span>
        </el-menu-item>
        <el-menu-item index="/boss">
          <i class="el-icon-coin"></i>
          <span>查看流水</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- 主体内容：可滚动 -->
    <el-container class="main-area">
      <el-header class="header-bar">
        <div class="left">点餐系统</div>
        <div class="right">
          <el-button type="danger" size="small" @click="logout">
            退出登录
          </el-button>
        </div>
      </el-header>

      <el-main class="main-scroll">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router'
import { computed } from 'vue'
import { ElMessage } from 'element-plus'

const route = useRoute()
const router = useRouter()

// 当前激活菜单
const activeMenu = computed(() => route.path)

// 退出登录
const logout = () => {
  localStorage.removeItem('employeeId')
  localStorage.removeItem('storeId')
  ElMessage.success('已退出登录')
  router.push('/login')
}
</script>

<style scoped>
/* 整体布局 */
.layout {
  height: 100vh;
}

/* 侧边栏 */
.sidebar {
  height: 100vh;
  position: sticky;
  top: 0;
  background: #f8f8f8;
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
}

/* LOGO 区域 */
.logo-box {
  text-align: center;
  padding: 16px 0 8px;
}
.title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
}
.sidebar-img {
  width: 80%;
  height: auto;
  display: block;
  margin: 0 auto 12px;
}

/* 右侧主体 */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid #ddd;
  height: 60px;
}
.main-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
</style>